package com.taotao.thread.Test1;

/**
 * @author wangjin
 * @title: Test2
 * @projectName thread
 * @description:线程的方法
 * @date 2022/5/3 0003 12:13
 */
public class Test2 {
    public static void main(String[] args) {
      //  testSleep();
     //     testyield();
        testJoin();
    }

    private static void testJoin() {
       Thread t1= new Thread(()->{
            for (int i = 0; i < 100; i++) {
                System.out.println("A"+i);
                try {
                    Thread.sleep(500);
                }catch (Exception e){
                    e.getMessage();
                }
            }
        });
        Thread t2= new Thread(()->{
            for (int i = 0; i < 100; i++) {
                System.out.println("t2"+i);
                try {
                    t1.join();
                    Thread.sleep(500);
                }catch (Exception e){
                    e.getMessage();
                }
            }
        });
        t1.start();
        t2.start();
    }

    private static void testyield() {
        new Thread(()->{
            for (int i = 0; i < 100; i++) {
                System.out.println("A"+i+Thread.currentThread());
                try {
                  if(i%10==0){
                      Thread.yield();
                  }
                }catch (Exception e){
                    e.getMessage();
                }
            }
        },"yeild").start();
    }

    /**
     * @Author wangjin
     * @Description //当前线程暂停一段时间让别的线程去执行，sleep是怎么复活的，由你的睡眠时间自动复活
     * @Date 2022/5/3 0003
     * @Param []
     * @return void
     **/
    private static void testSleep() {
        new Thread(()->{
            for (int i = 0; i < 100; i++) {
                System.out.println("A"+i);
                try {
                    Thread.sleep(500);
                }catch (Exception e){
                    e.getMessage();
                }
            }
        },"买多了").start();
    }
    
}
